import json
from sklearn.datasets import load_iris
from PyCmpltrtok.common import sep

if __name__ == '__main__':

    # data sets
    sep('Load Iris')
    xy = load_iris()
    sep('The data')
    print(xy)
    sep('Save JSON')
    with open('load_iris.tmp.json', 'w', encoding='utf8') as f:
        
        # TypeError: Object of type ndarray is not JSON serializable
        xy.data = xy.data.tolist()
        xy.target = xy.target.tolist()
        xy.target_names = xy.target_names.tolist()
        
        json.dump(xy, f, ensure_ascii=False)
    sep('All over')
